package by.onlinernews.loader;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.Log;

public class ImageLoadHelper {

	public Bitmap LoadImage(String urlString){
		try {
            InputStream is = fetch(urlString);
            Log.d("drawable", "load Bitmap : " + urlString);
           // Drawable drawable = Drawable.createFromStream(is, urlString); 
            Bitmap b = BitmapFactory.decodeStream(is);
           // int higth = drawable.getIntrinsicHeight()*MainActivity.width/drawable.getIntrinsicWidth();
          //  Log.d("drawable", "Bounds: right: " + drawable.getIntrinsicWidth() + " bottom: "+drawable.getIntrinsicHeight());                
          //  drawable.setBounds(0, 0, 0 + MainActivity.width, 0 
          //          + higth); 
            return b;
        } catch (Exception e) {
            return null;
        } 
    }

    private InputStream fetch(String urlString) throws MalformedURLException, IOException {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet request = new HttpGet(urlString);
        HttpResponse response = httpClient.execute(request);
        return response.getEntity().getContent();
    }
}
